import React, { useEffect, useState } from 'react'

export default function Counter() {
  //声明状态
  let [count, setCount] = useState(0);
  //useEffect
  useEffect(() => {
    let timer = setInterval(() => {
      // console.log('run run');
      //更新状态
      setCount(count => count + 1);
    }, 1000);

    return () => {
      clearInterval(timer);
    }
  }, [])
  return (
    <h1>{count}</h1>
  )
}
